package com.cat.greedyAlgorithm;

import java.util.HashMap;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/partition-array-into-k-distinct-groups/description/
 * @create 2025/10/12 13:44
 * @since JDK17
 */

public class Solution80 {
    public boolean partitionArray(int[] nums, int k) {
        int n = nums.length, m = n / k;
        if (n % k != 0) {
            return false;
        }
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int num : nums) {
            map.merge(num, 1, Integer::sum);
        }

        for (var num : map.values()) {
            if (num > m) {
                return false;
            }
        }
        return true;
    }
}
